function greeter(person: string) {
    return "Hello, " + person;

}

let user: string = "Jane User";

globalThis.console.log(greeter(user));
enum Color {red, Green, Blue};
let c: Color = Color.Green;
globalThis.console.log(typeof c);

let someValue: any = 10;

let strLength: number = (<number>someValue) + 10;

globalThis.console.log(typeof strLength);

type CC = {aa: string, bb?: number};
function fff({aa,bb = 0}: CC = {aa: '',bb: 10}): void {
    console.log(aa);
    console.log(bb);
}
fff({aa: 'ss'});

function twoSum(nums: number[], target: number): number[] {
    const length: number = nums.length;
   let arr: number[] = [];
   let i: number = 0;
   while(i < length) {
        let num1: number = target - nums[i];
        const num2: number = nums.findIndex(el => el === num1);
        if((num2 >= 0) && (num2 != i)) {
            arr = [i,num2];
            break;
        }
       i++;
   }
   return arr;
};
const nums: number[] = [-1,-2,-3,-4,-5];
let renums: number[] = [];
renums = twoSum(nums,-8);
console.log(renums);

function fun(a: number, b: number): number { return a + b; }
let aaa: (x: number, y: number) => number = fun;
let aaaa: number = aaa(3,5);
console.log(aaaa);

function fun1(a: number, b = 10) {
    console.log(a,b);
    
}

fun1(10);

function fun22(a: number, ...other: number[]): boolean { return other.every((el: number) => a < el)}
let fll: boolean = fun22(2,2,3,4);
console.log(fll);



let suits = ["hearts", "spades", "clubs", "diamonds"];

function pickCard(x: {suit: string; card: number; }[]): number;
function pickCard(x: number): {suit: string; card: number; };
function pickCard(x: any): any {
    // Check to see if we're working with an object/array
    // if so, they gave us the deck and we'll pick the card
    if (typeof x == "object") {
        let pickedCard = Math.floor(Math.random() * x.length);
        return pickedCard;
    }
    // Otherwise just let them pick the card
    else if (typeof x == "number") {
        let pickedSuit = Math.floor(x / 13);
        return { suit: suits[pickedSuit], card: x % 13 };
    }
}

let myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }];
let pickedCard1 = myDeck[pickCard(myDeck)];
console.log(pickedCard1.card,pickedCard1.suit);


let pickedCard2 = pickCard(15);
console.log(pickedCard2.card,pickedCard2.suit);

function funff(x: number): number;
      function funff(x: string): boolean;
      function funff(x: any): any {
         if(typeof x == "number") {return x*10;}
         if(typeof x == "string") {return true;}
      }
console.log(funff('10'));

interface AA <T,U> {
    name: T,
    content: U,
 }
 function funcf <V,M> (name: V, content: M): AA<V,M> {
    let data: AA <V,M> = {
       name,
       content,
    }
    return data;
 }
 let ffa: object = funcf('xxx',{password: '654321',phone: '1234455667677'});// {name: 'xxx',content: {password: '654321',phone: '1234455667677'}}
console.log(ffa);


enum Direction {
    Up = "1",
    Down = "2",
    Left = "3",
    Right = "4",
 }
 let Enum: string = Direction.Up;
 console.log(Enum);

 let fun1111: (num: number) => number = fun;
 




